package org.jeecg.modules.basedata.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.entity.basedata.*;
import org.jeecg.modules.basedata.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @Description: Api调用
* @Author: jeecg-boot
* @Date:   2019-08-04
* @Version: V1.0
*/
@Slf4j
@Api(tags="basedata调用控制器")
@RestController
@RequestMapping("/api/basedata")
public class BaseDataApiController {
    @Autowired
    @Lazy
    private IBaseCustomerService baseCustomerService;
    @Autowired
    @Lazy
    private IBaseRoomService baseRoomService;
    @Autowired
    @Lazy
    private IBaseProjectService baseProjectService;
    @Autowired
    @Lazy
    private IBaseFloorService baseFloorService;
    @Autowired
    @Lazy
    private IBaseFeeRuleService baseFeeRuleService;
    @Autowired
    private IRentContractService rentContractService;

    @ApiOperation(value="getBaseFeeRuleById", notes="getBaseFeeRuleById")
    @PostMapping(value = "/getBaseFeeRuleById")
    public BaseFeeRule getBaseFeeRuleContractById (String feeRuleId){
        log.info( " BASEDATA getBaseFeeRuleById 被远程调用");
        return baseFeeRuleService.getById(feeRuleId);
    }

    @ApiOperation(value="getByRoomIds", notes="getByRoomIds")
    @PostMapping(value = "/getByRoomIds")
    public List<BaseRoom> getByRoomIds (String[] roomIds){
        log.info( " BASEDATA getByRoomIds 被远程调用");
        return baseRoomService.getByRoomIds(roomIds);
    }

    @ApiOperation(value="getByRoomIdsLarge", notes="getByRoomIdsLarge")
    @PostMapping(value = "/getByRoomIdsLarge")
    public List<BaseRoom> getByRoomIdsLarge (@RequestBody String  jsonParam){
        log.info( " BASEDATA getByRoomIdsLarge 被远程调用{}",jsonParam);
        if (jsonParam != null){
            jsonParam = jsonParam.replace("\"","");
            String[] ids = jsonParam.split(",");
            return baseRoomService.getByRoomIds(ids);
        } else {
            log.error("getByRoomIdsJson 接受参数为空");
            return null;
        }
    }

    @ApiOperation(value="getByCustomerId", notes="getByCustomerId")
    @PostMapping(value = "/getByCustomerId")
    public String getByCustomerId (@RequestParam("roomId") String roomId){
        log.info("BASEDATA getByCustomerId 业主ID查询被远程调用");
        return   baseCustomerService.getByCustomerId(roomId);
    }

    @ApiOperation(value="getByTenantId", notes="getByTenantId")
    @PostMapping(value = "/getByTenantId")
    public String getByTenantId (@RequestParam("roomId") String roomId){
        log.info("BASEDATA getByTenantId 租户ID查询被远程调用");
        return   baseCustomerService.getByTenantId(roomId);
    }


    /**
     * 获取当前用户权限下的所有小区 - 权限未加 TODO
     * @param userId
     * @return
     */
    @ApiOperation(value="findProjectList", notes="findProjectList")
    @PostMapping(value = "/findProjectList")
    public List<BaseProject> findProjectList(@RequestParam("userId") String userId){
        log.info("BASEDATA findProjectList 被远程调用");
        return  baseProjectService.findProjectList(userId);
    }

    @ApiOperation(value="getProjectById", notes="getProjectById")
    @PostMapping(value = "/getProjectById")
    public BaseProject getProjectById(@RequestParam("projectId") String projectId){
        BaseProject project = baseProjectService.getProjectById(projectId);
        return project;
    }

    @ApiOperation(value="queryByRoomId", notes="queryByRoomId")
    @PostMapping(value = "/queryByRoomId")
    public BaseCustomer queryByRoomId (@RequestParam("roomId") String roomId){
        log.info("BASEDATA queryByRoomId 业主查询被远程调用");
        return   baseCustomerService.queryByRoomId(roomId) ;
    }

    @ApiOperation(value="getRoomById", notes="getRoomById")
    @PostMapping(value = "/getRoomById")
    public BaseRoom getRoomById (@RequestParam("roomId") String roomId){
        log.info("BASEDATA getRoomById 房间查询被远程调用");
        return  baseRoomService.getById(roomId) ;
    }
    @ApiOperation(value="findProjectAll", notes="findProjectAll")
    @PostMapping(value = "/findProjectAll")
    public List<BaseProject> findProjectAll(){
        return  baseProjectService.findProjectAll() ;
    }

    @ApiOperation(value="getByProjectIdName", notes="getByProjectIdName")
    @PostMapping(value = "/getByProjectIdName")
    public BaseFloor getByProjectIdName (@RequestParam("projectId") String projectId,@RequestParam("name") String name){
        log.info("BASEDATA getByProjectIdName 楼栋查询被远程调用");
        return baseFloorService.getByProjectIdName(projectId,name);
    }

    @ApiOperation(value="getByFloorIdName", notes="getByFloorIdName")
    @PostMapping(value = "/getByFloorIdName")
    public BaseRoom getByFloorIdName (@RequestParam("floorId") String floorId,@RequestParam("name") String name){
        return baseRoomService.getByFloorIdName(floorId,name);
    }

}
